<?php

namespace App\Http\Controllers;

use App\Http\Model\Hint;
use App\Http\Model\OutJson;
use App\Http\Model\SystemConfig;
use App\Http\Services\CommonPrivateMsgServices;
use App\Http\Services\CommonSystemMsgServices;
use App\Http\Services\Message\MessageServices;
use App\Http\Services\MsgServices;
use App\Http\Services\UserServices;
use App\Lib\rc;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

/**
 * 融云审核回调
 *
 * Created on 2021/12/13 19:19
 * @Author <yuxiang.zhu@asiainnovations.net>
 */
class RongCloudAuditController extends BaseController
{
    /**
     * 审核结果回调
     *
     * 文档地址：https://doc.rongcloud.cn/imserver/server/v1/security/audit-result
     * Created at 2021/12/13 17:22
     * @Author <yuxiang.zhu@asiainnovations.net>
     * @param Request $request
     */
    public function contentAuditCallback(Request $request)
    {
        $params = $request->all();
        if (!isset($params['result'])) {
            OutJson::outJsonResult(Hint::SUCCESS);
        }

        // result=审核结果，10000 为正常;10001 为审核不通过
        if (intval($params['result']) == 10000) {// 审核通过
            OutJson::outJsonResult(Hint::SUCCESS);
        }

        $content = json_decode($params['content'], true);
        $fromUserId = intval($content['fromUserId']);// 发送者user_id
        //判断版本
        // if ($this->checkWhetherCanSend($fromUserId) === false) {
        //     OutJson::outJsonResult(Hint::SUCCESS);
        // }

        write_log('contentAuditCallback', 'contentAuditCallback', $content);
        
        $targetId = intval($content['targetId']);// 接收者user_id
        $conversationType = $content['conversationType'];// 会话类型，二人会话是 PERSON、群组会话是 GROUP 、聊天室会话是 TEMPGROUP

        $msgServices = new MsgServices();

        if (strtolower($conversationType) == 'person') {
            //给自己发送
            $text = "你发送的内容含有敏感词汇，已经被屏蔽，对方无法查看";
            $msgServices->sendPrivateChatViolation($targetId, $fromUserId, $text);

            //给对方发送
            $text = "对方发送的内容含敏感词汇，已屏蔽该条内容";
            $msgServices->sendPrivateChatViolation($fromUserId, $targetId, $text);
        } else {
            //其他类型消息暂不处理
            /*$data = [
                'fromUserId' => $fromUserId,
                'targetId' => $targetId,
                'fromMsg' => '你发送的内容含有敏感词汇，已经被屏蔽，对方无法查看',
                'targetMsg' => '对方发送的内容含敏感词汇，已屏蔽该条内容',
                'conversationType' => $conversationType,
                'objectName' => $content['objectName'], // 消息类型，文本消息 RC:TxtMsg 、图片消息 RC:ImgMsg 、语音消息 RC:VcMsg、高清语音消息 RC:HQVCMsg、小视频消息 RC:SightMsg
            ];
            (new CommonSystemMsgServices())->sendSystemMsgToUserV2($fromUserId, 80052, $data, 'kk:chat_violation_tip_system');
            */
        }

        OutJson::outJsonResult(Hint::SUCCESS);
    }

}